layui.use(['jquery','layer','form'],function(){
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var user = JSON.parse(localStorage.getItem('user'));
    var courseId = JSON.parse(localStorage.getItem('courseId'));
    var recordId = JSON.parse(localStorage.getItem('recordId'));
    var userId = user.data.userId;
    var userName = user.data.account;
    //关闭按钮点击事件
    $('#cancel').click(function () {
        var layer = parent.layer;
        layer.close(layer.index);
    });
    form.on('submit(define)',function (data) {
        var result = data.field.result;
        var remarks = data.field.remarks;
        var auditType;
        if(result == 1){
            auditType = 2;
        }else if(result == 3){
            auditType = 3;
        };
        var audit = {
            type:auditType,
            userId:userId,
            remark:remarks,
            examineType:2,
            userName:userName,
            examineId:recordId
        };
        $.ajax({
            url:'/examine/updateCourseRecord',
            type:'post',
            dataType:'json',
            data:{'courseId':courseId,'courseCstatus':result,'updateId':userId},
            success: function (data) {
                updateRecord(result,remarks);
            }
        })
        //修改审核状态
        function updateRecord() {
            $.ajax({
                url: '/examine/updateRecordResult',
                type: 'post',
                dataType: 'json',
                data:{'id':recordId,'implementId':userId,'result':result,'remarks':remarks},
                success: function (data) {
                    addAuditLog();
                }
            });
        }
        //添加审核日志
        function addAuditLog() {
            $.ajax({
                url: '/examine/addAuditLog',
                type: 'post',
                dataType: 'json',
                data:audit,
                success: function (data) {
                    var layer = parent.layer;
                    layer.close(layer.index);
                }
            });
        }
        return false;
    });
})